| Conditions | 1 |
| Paths | 27 |
| Total Lines | 103 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global API */ |
||
| 36 | .controller('SettingsCtrl', ['$scope', '$rootScope', 'Settings', '$location', function ($scope, $rootScope, Settings, $location) { |
||
| 37 | $scope.settings = { |
||
| 38 | nextcloud_host: '', |
||
| 39 | nextcloud_username: '', |
||
| 40 | nextcloud_password: '', |
||
| 41 | ignoreProtocol: true, |
||
| 42 | ignoreSubdomain: true, |
||
| 43 | ignorePort: true, |
||
| 44 | ignorePath: true, |
||
| 45 | generatedPasswordLength: 12, |
||
| 46 | remember_password: true, |
||
| 47 | remember_vault_password: true, |
||
| 48 | refreshTime: 60, |
||
| 49 | disable_browser_autofill: true, |
||
| 50 | debug: false |
||
| 51 | }; |
||
| 52 | $scope.errors = []; |
||
| 53 | |||
| 54 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
| 55 | $scope.errors = []; |
||
| 56 | if (settings) { |
||
| 57 | $scope.settings = angular.copy(settings); |
||
| 58 | } |
||
| 59 | |||
| 60 | $scope.get_vaults = function () { |
||
| 61 | if (!$scope.settings.hasOwnProperty('nextcloud_host') || !$scope.settings.hasOwnProperty('nextcloud_password') || !$scope.settings.hasOwnProperty('nextcloud_username')) { |
||
| 62 | return; |
||
| 63 | } |
||
| 64 | PAPI.username = $scope.settings.nextcloud_username; |
||
| 65 | PAPI.password = $scope.settings.nextcloud_password; |
||
| 66 | PAPI.host = $scope.settings.nextcloud_host; |
||
| 67 | $scope.extension = API.runtime.getManifest().name + ' extension ' + API.runtime.getManifest().version; |
||
| 68 | PAPI.getVaults(function (vaults) { |
||
| 69 | $scope.errors = []; |
||
| 70 | var save_btn = jQuery('#save'), |
||
| 71 | login_required = jQuery('.login-req'); |
||
| 72 | if (vaults.hasOwnProperty('error')) { |
||
| 73 | |||
| 74 | var errors = API.i18n.getMessage('invalid_response_from_server', [vaults.result.status, vaults.result.statusText]); |
||
| 75 | $scope.errors.push(errors); |
||
| 76 | login_required.hide(); |
||
| 77 | save_btn.hide(); |
||
| 78 | $scope.$apply(); |
||
| 79 | return; |
||
| 80 | |||
| 81 | } |
||
| 82 | login_required.show(); |
||
| 83 | save_btn.show(); |
||
| 84 | $scope.vaults = vaults; |
||
| 85 | $scope.$apply(); |
||
| 86 | |||
| 87 | }); |
||
| 88 | }; |
||
| 89 | |||
| 90 | $scope.$watch('[settings.nextcloud_host, settings.nextcloud_username, settings.nextcloud_password]', function () { |
||
| 91 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
| 92 | $scope.get_vaults(); |
||
| 93 | } |
||
| 94 | }, true); |
||
| 95 | |||
| 96 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
| 97 | $scope.get_vaults(); |
||
| 98 | } |
||
| 99 | $scope.$apply(); |
||
| 100 | }); |
||
| 101 | |||
| 102 | $scope.saving = false; |
||
| 103 | $scope.saveSettings = function () { |
||
| 104 | $scope.errors = []; |
||
| 105 | var settings = angular.copy($scope.settings); |
||
| 106 | try { |
||
| 107 | /** global: PAPI */ |
||
| 108 | PAPI.decryptString(settings.default_vault.challenge_password, settings.vault_password); |
||
| 109 | } catch (e) { |
||
| 110 | $scope.errors.push(API.i18n.getMessage('invalid_vault_password')); |
||
| 111 | return; |
||
| 112 | } |
||
| 113 | |||
| 114 | $scope.saving = true; |
||
| 115 | API.runtime.sendMessage(API.runtime.id, {method: "saveSettings", args: settings}).then(function () { |
||
| 116 | setTimeout(function () { |
||
| 117 | window.location = '#!/'; |
||
| 118 | $scope.saving = false; |
||
| 119 | }, 750); |
||
| 120 | }); |
||
| 121 | }; |
||
| 122 | |||
| 123 | $scope.removeSite = function (site) { |
||
| 124 | var idx = $scope.settings.ignored_sites.indexOf(site); |
||
| 125 | $scope.settings.ignored_sites.splice(idx, 1); |
||
| 126 | }; |
||
| 127 | |||
| 128 | $scope.ignoreSite = ''; |
||
| 129 | $scope.addSite = function (site) { |
||
| 130 | $scope.settings.ignored_sites.push(site); |
||
| 131 | $scope.ignoreSite = ''; |
||
| 132 | }; |
||
| 133 | |||
| 134 | |||
| 135 | $scope.cancel = function () { |
||
| 136 | window.location = '#!/'; |
||
| 137 | }; |
||
| 138 | }]); |
||
| 139 | }()); |
||
| 141 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.